<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\bootstrap\Modal;

/* @var $this yii\web\View */
/* @var $searchModel app\models\WmActiveSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Wm Actives');
$this->params['breadcrumbs'][] = $this->title;
$pid = Yii::$app->request->get('WmActiveSearch');
$pid = $pid['pid'];
?>
<div class="wm-active-index">
    <?php

    Modal::begin([
        'header' => '<h2>Hello world</h2>',
    ]);
    echo 'Say hello...';
    Modal::end();
    ?>


    <p>
        <?php
        echo Html::a(Yii::t('app', 'back'), ['product/index'], ['class' => 'btn btn-success'])
        ?>
    </p>

    <?php echo $this->render('_search', ['model' => $searchModel]); ?>

    <?php
    if (Yii::$app->user->identity->is_admin == 1):
        ?>
        <?php
    endif;
    ?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
//        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
//            'id',
//            'times',
            [
                'attribute' => 'times',
                'format' => 'raw',
                'value' => 'times',
                'label' => '日期',
            ],
            [
                'attribute' => 'num',
                'format' => 'raw',
                'value' => 'num',
                'label' => '激活数量',
            ],
            [
//                'attribute' => 'created_at',
                'format' => 'raw',
                'value' => 'created_at',
                'visible' => Yii::$app->user->identity->is_admin == 1,
                'label' => '创建日期',
            ],
//            'num',
//            'created_at:datetime',
            ['class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'options' => ['width' => '60px;'],
                'template' => '{update}{modal}',
                'visible' => Yii::$app->user->identity->is_admin == 1,
                'buttons' => [
                    'update' => function ($url, $model) {

//                        return $model['empty'];
                        if (empty($model['empty'])) {
                            return Html::a('<span class="">' . Yii::t('app', 'Update') . '</span>', ['update', 'id' => $model['id'], 'ajax' => 1], [
                                'class' => 'glyphicon', 'data-toggle' => 'modal', 'data-target' => '#ajax' . $model['id']]);
                        } else {
                            return Html::a('<span class="">' . Yii::t('app', 'Update') . '</span>', ['active/create', 'pid' => $model['pid'], 'times' => $model['times'], 'ajax' => 1], [
                                'class' => 'glyphicon', 'data-toggle' => 'modal', 'data-target' => '#ajax' . $model['id']

                            ]);


                        }


                    },
                    'modal' => function ($url, $model) {
                        return '<div class="modal fade" id="ajax' . $model['id'] . '">
                                    <div class="modal-dialog">
                                        <div class="modal-content">

                                        </div>
                                    </div>
                                </div>';
                    },
                ]
            ],
        ],
    ]); ?>
</div>
